#pragma once

#include "action.h"
#include "templatearray.h"

/** use this when doing batch changes, like modifying many pixels. TODO use it or lose it... */
template<class ACTION_TYPE>
class ActionGroup : public Action
{
protected:
	TemplateArray<ACTION_TYPE> m_elements;
public:
	ActionGroup(const int & a_size):m_elements(a_size){}
	ACTION_TYPE * get(const int & a_index)
	{
		return &m_elements.get(a_index);
	}
	void set(const int & a_index, const ACTION_TYPE & a_action)
	{
		m_elements.set(a_index, a_action);
	}
	bool execute()
	{
		bool executed = false;
		for(int i = 0; i < m_elements.size(); ++i)
		{
			executed |= get(i)->execute();
		}
		return executed;
	}
	bool undo()
	{
		bool undone = false;
		for(int i = 0; i < m_elements.size(); ++i)
		{
			undone |= get(i)->undo();
		}
		return undone;
	}
	const char * getName(){return m_elements.get(0).getName();}
};
